#coding=utf-8
from rest_framework import serializers
from datetime import datetime
from .models import *
import requests
import datetime
import time
from django.db.models import *
from datareport.models import *

RecordUrl = "14.119.109.232:88/recordFile/"
PicUrl  ="180.97.83.70/resource/kshow_v3/res_songs/res_aam/song/"

class RecordFileSerializer(serializers.ModelSerializer):
    UserInfo =  serializers.SerializerMethodField()
    recordUrl = serializers.SerializerMethodField()
    picUrl = serializers.SerializerMethodField()
    songInfo = serializers.SerializerMethodField()
    
    def get_songInfo(self,obj):
        result=song_base.objects.filter(song_no=obj.songId).values("name","singer_names")
	if result:
	    return (result[0]["name"],result[0]["singer_names"])
	return ("","")
    def get_UserInfo(self,obj):
        print obj.uid
        result=UserInfo.objects.filter(UID=obj.uid).values("NickName","HeadImgUrl")
	if result:
	    return (result[0]["NickName"],result[0]["HeadImgUrl"])
	else:
	    return ("","")
    def get_recordUrl(self,obj):
        #return "14.119.109.232:88/recordFile/"+str(obj.uid)+"/"+obj.fileName
        return RecordUrl+str(obj.uid)+"/"+obj.fileName
    def get_picUrl(self,obj):
        #return "180.97.83.70/resource/kshow_v3/res_songs/res_aam/song/%s/%s"%(str(obj.songId),str(obj.songId))+".png"
        return PicUrl+(str(obj.songId)+'/'+str(obj.songId))+".png"
    class Meta:
        model = RecordFile
	fields = "__all__"

